package co.com.fenoco.encuentas.servicios;

import java.util.Properties;

import javax.naming.InitialContext;

public class ServiceLocator {
	private static ServiceLocator instance;

	private ServiceLocator() {

	}

	public static synchronized ServiceLocator getInstance() {
		if (instance == null)
			instance = new ServiceLocator();
    
		return instance;
	}

	/**
	 * Localiza un recurso en el servidor dado su nombre JNDI
	 * 
	 * @param jndiName
	 *            Nombre JNDI del recurso
	 * @return Referencia remota o local al recurso en el servidor
	 */
	public Object lookup(String jndiName) throws Exception {
		Properties properties = new Properties();
		properties.setProperty("java.naming.factory.initial",
				"org.jnp.interfaces.NamingContextFactory");
		properties.setProperty("java.naming.provider.url", "localhost:1099");
		properties.setProperty("java.naming.factory.url.pkgs",
				"org.jboss.naming:org.jnp.interfaces");
		InitialContext context = new InitialContext(properties);
		return context.lookup(jndiName);
	}
}
